package com.maila.calltaxi.view;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.maila.calltaxi.R;
import com.zhy.autolayout.utils.AutoUtils;

/**
 * Created by Administrator on 2017/7/11.
 */

public class WaitCarPop extends PopupWindow {
    private View mMenuView;
    TextView btn_cancle,btn_wait;

    public WaitCarPop(final Context context, final ActionListener actionListener) {
        super(context);
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mMenuView = inflater.inflate(R.layout.view_wait_car, null);
        AutoUtils.autoSize(mMenuView);
        btn_cancle= (TextView) mMenuView.findViewById(R.id.cancel_call);
        btn_wait= (TextView) mMenuView.findViewById(R.id.continue_waiting);
        btn_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                actionListener.waitorcancle(0);
                dismiss();
            }
        });
        btn_wait.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                actionListener.waitorcancle(1);
                dismiss();
            }
        });
        //设置SelectPicPopupWindow的View
        this.setContentView(mMenuView);
//            设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
//            设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.sharepopupanimation);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(80000000);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
        //mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
        mMenuView.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {

                return true;
            }
        });
    }
    public interface  ActionListener{
        void waitorcancle(int action);
    }
}
